import { order } from "@mall/api-services"

const { OrderStatus, OrderDisputeStatus } = order

export const awaitingPaymentStatuses = [OrderStatus.Pending, OrderStatus.AwaitingPayment]
export const awaitingRefundStatuses = [OrderDisputeStatus.Applying, OrderDisputeStatus.Reapplying, OrderDisputeStatus.Disapproved, OrderDisputeStatus.Pending]
export const awaitingFulfillmentStatuses = [OrderStatus.AwaitingFulfillment]
export const awaitingPickupStatuses = [OrderStatus.PartiallyShipped, OrderStatus.Shipped, OrderStatus.AwaitingPickup]
export const awaitingReviewStatuses = [OrderStatus.Incomplete, OrderStatus.AwaitingReview]
export const completedStatuses = [OrderStatus.Completed]

export function isAwaitingPayment(status: order.OrderStatus): boolean {
  return status === OrderStatus.Pending || status === OrderStatus.AwaitingPayment
}

export function isAwaitingFulfillment(status: order.OrderStatus): boolean {
  return status === OrderStatus.AwaitingFulfillment
}

export function isPartiallyShipped(status: order.OrderStatus): boolean {
  return status === OrderStatus.PartiallyShipped
}

export function isShipped(status: order.OrderStatus): boolean {
  return status === OrderStatus.Shipped
}

export function isAwaitingPickup(status: order.OrderStatus): boolean {
  return status === OrderStatus.AwaitingPickup
}

export function isCancelled(status: order.OrderStatus): boolean {
  return status === OrderStatus.Cancelled
}

export function isClosed(status: order.OrderStatus): boolean {
  return status === OrderStatus.Closed
}

export function isDeclined(status: order.OrderStatus): boolean {
  return status === OrderStatus.Declined
}

export function isCompleted(status: order.OrderStatus): boolean {
  return status === OrderStatus.Completed
}

export function getStatusLabel(status: order.OrderStatus): string {
  if (isAwaitingPayment(status)) {
    return "等待买家付款"
  } else if (isAwaitingFulfillment(status)) {
    return "等待商家发货"
  } else if (isPartiallyShipped(status)) {
    return "卖家部分已发货"
  } else if (isShipped(status)) {
    return "卖家已发货"
  } else if (isCancelled(status) || isDeclined(status)) {
    return "交易取消"
  } else if (isClosed(status)) {
    return "交易关闭"
  } else if (isCompleted(status)) {
    return "交易完成"
  }
  return "未知状态"
}
